<?php
/**
 * 优惠券导入【申请】 jd.union.open.coupon.importation
 *
 * See: https://union.jd.com/openplatform/api/696
 * User: Ken.Zhang <kenphp@yeah.net>
 * Date: 2019-05-12
 */
class UnionOpenCouponImportationRequest {

    /**
     * 商品ID
     */
    private $skuId;

    /**
     * 优惠券链接
     */
    private $couponLink;

    /**
     * 请求参数
     */
    public $apiParams = [];

    public function setSkuId($sku_id)
    {
        $this->skuId = $sku_id;
        $this->apiParams['couponReq']['skuId'] = $sku_id;
    }

    public function getSkuId()
    {
        return $this->skuId;
    }

    public function setCouponLink($coupon_link)
    {
        $this->couponLink = $coupon_link;
        $this->apiParams['couponReq']['couponLink'] = $coupon_link;
    }

    public function getCouponLink()
    {
        return $this->couponLink;
    }

    public function getApiMethodName()
    {
        return 'jd.union.open.coupon.importation';
    }

    /**
     * 解析结果
     *
     * @param   string      $response
     * @throws  Exception
     * @return  mixed
     */
    public function getResult($response)
    {
        $responseKey = str_replace('.', '_', $this->getApiMethodName()) . '_response';

        $response = @json_decode($response, true);
        if (!array_key_exists($responseKey, $response))
            $resp = $response['errorResponse'];
        else {
            $response[$responseKey]['result'] = json_decode($response[$responseKey]['result']);

            $resp = $response[$responseKey];
        }

        return $resp;
    }

}